﻿#ifndef ANALYZER_ALGORITHMONNXYOLO8_H
#define ANALYZER_ALGORITHMONNXYOLO8_H

#include <string>
#include <vector>
#include <mutex>
#include <queue>
#include "Algorithm.h"
#include <onnxruntime_cxx_api.h>

namespace AVSAnalyzer 
{
	class Config;
	class OnnxRuntimeEngine
	{
	public:
		explicit OnnxRuntimeEngine(const AlgorithmConfig& algorithmConfig);
		~OnnxRuntimeEngine();
	public:
		bool runInference(cv::Mat& image, std::vector<DetectObject>& detects);	// 执行目标检测推理

	private:
		const AlgorithmConfig& mAlgorithmConfig;
		// 配置参数
		float mScoreThreshold;
		float mNmsThreshold;
		std::vector<int> mInputSize;
		std::vector<float> mMean;
		std::vector<float> mStd;
		float mPreprocessScale;

		// 模型信息
		std::vector<std::string> mInputNodeNames;
		std::vector<std::string> mOutputNodeNames;
		int mInputWidth;
		int mInputHeight;
		int mOutputDim;    // 84: 类别数+坐标数
		int mOutputRow;    // 8400: anchor数量

		// ONNX Runtime 相关
		Ort::Env mEnv{ nullptr };
		Ort::SessionOptions mSessionOptions{ nullptr };
		Ort::Session mSession{ nullptr };
	};
	class AlgorithmOnnxRuntimeV8 : public Algorithm
	{
	public:
		AlgorithmOnnxRuntimeV8(const AlgorithmConfig& algorithmConfig);
		virtual ~AlgorithmOnnxRuntimeV8();
	public:
		virtual bool objectDetect(cv::Mat& image, std::vector<DetectObject>& detects) override;
	private:
		std::mutex mMtx;
		OnnxRuntimeEngine* mEngine;
	};
}
#endif //ANALYZER_ALGORITHMONNXYOLO8_H

